<include file="../header" />
<div class="wrapper">
    <div class="header text-center font-16">
        公共报修
        <div class="iconfont icon-zuo go_index"></div>
    </div>
    <div class="history-list">
        <div class="addimg clearfix">
            <div class="load-img pull-left" id="repair_image">
                <div class="img">
                    <div class="load text-center">
                        +
                    </div>
                </div>
            </div>
        </div>
        <div class="repair-list describe-content">
            <input type="text" placeholder="请描述报修内容" id="content">
        </div>
        <input type="hidden" id="public_id" value="{BEESCRM:$data.public_id}">
        <input type="hidden" id="community_id" value="{BEESCRM:$community.community_id}">
        <input type="hidden" id="building_id" value="{BEESCRM:$building.building_id}">
        <input type="hidden" id="floor_id" value="{BEESCRM:$floor.floor_id}">
        <div class="repair-list gray2">
            报修项目
            <p id="public_name" style="color:#000;">{BEESCRM:$data.remark}</p>
        </div>
        <div class="repair-list gray2">
            报修地址
            <p style="color:#000;">
                <span id="community_name">{BEESCRM:$community.community_name}</span>
                <span id="building_name">{BEESCRM:$building.building_name}</span>
                <span id="floor_name">{BEESCRM:$floor.floor_name}</span>
            </p>
        </div>
        <input type="hidden" id="serverId" value="">
    </div>
    <div class="flex repair-btn">
        <a href="#" class="btn text-center btn-left" id="order_submit">提交</a>
        <a href="javascript:history.back();" class="btn text-center btn-right gray-bg">取消</a>
    </div>
</div>
<include file="../getphotos"/>
<script src="/assets/repaireast/js/layer.js"></script>
<script src="/assets/repaireast/js/public.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.ui.widget.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.fileupload.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.iframe-transport.js"></script>
<script>
   /* $('.img').click(function () {
        $('.file').click();
    })

    //图片上传
    $(".file").fileupload({
        url:"/Base/Common/upload",//文件上传地址，当然也可以直接写在input的data-url属性内
//        beforeSend:function(){
//            $('.load').show();
//        },
        done:function(e,result){
            //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
            //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
            //返回的数据在result.result中，假设我们服务器返回了一个json对象
            var data=$.parseJSON(result.result);
            if(data.status=='S'){
                var html = '<img src="'+data.url+'">';
                $('#repair_image .img').html(html);
            }else{
                fm.alert(data.message);
                return false;
            }
        }
    });*/
   $(function() {
       var serverId = '';
       $('.img').click(function () {
           wx.ready(function () {
               wx.chooseImage({
                   count: 1, // 默认9
                   sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                   sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                   success: function (res) {
                       var localIds = res.localIds;
                       $('#repair_image .img').html('<img src="' + localIds[0] + '">');

                       var localId = localIds.pop();
                       wx.uploadImage({
                           localId: localId, // 需要上传的图片的本地ID，由chooseImage接口获得
                           isShowProgressTips: 1, // 默认为1，显示进度提示
                           success: function (res) {
                               serverId = res.serverId; // 返回图片的服务器端ID
                               ('#serverId').val(serverId);
                           }
                       });
                   }
               });
           });
       })
   })

    //提交数据
    $('#order_submit').click(function(){
        var image = $('#repair_image img').attr('src');
        if (!image){
            fm.alert('请上传报修图片！');
            return false;
        }
        var content = $('#content').val();
        if (!content){
            fm.alert('请描述报修内容！');
            return false;
        }
        var serverId = $('#serverId').val();
        $.ajax({
            type:'post',
            url:"/Repaireast/RepaireastWorker/doPublicRepair",
            dataType:'json',
            data:{
                'image' : image,
                'content' : content,
                'public_id' : $('#public_id').val(),
                'public_name' : $('#public_name').text(),
                'community_id' : $('#community_id').val(),
                'community_name' : $('#community_name').text(),
                'building_id' : $('#building_id').val(),
                'building_name' : $('#building_name').text(),
                'floor_id' : $('#floor_id').val(),
                'floor_name' : $('#floor_name').text(),
                'serverId':serverId
            },
            success:function(data){
                //var res = JSON.parse(data);
                if (data.status == 'S') {
                    fm.alert('操作成功!');
                    setTimeout(function(){
                        window.location.href=data.url;
                    },2000);                    
                }
                else {
                    fm.alert(res.message);
                }

            },
            error:function(){
                fm.alert('通讯失败，请稍后再试');
            }
        });
    });
</script>
<include file="../footer" />